﻿using System;
using System.Web.Mvc;

namespace Dexter.Web.Mvc.Filters {
	[AttributeUsage ( AttributeTargets.Method, AllowMultiple = false, Inherited = true )]
	public class AjaxOnlyAttribute : ActionFilterAttribute {
		/// <summary>
		/// Called by the ASP.NET MVC framework before the action method executes.
		/// </summary>
		/// <param name="filterContext">The filter context.</param>
		public override void OnActionExecuting ( ActionExecutingContext filterContext ) {
			var request = filterContext.HttpContext.Request;
			if (!request.IsAjaxRequest ( ))
				filterContext.Result = new HttpNotFoundResult ( "Only Ajax calls are permitted." );
		}
	}
}